package com.bc.bcbuyerapihttp.controller;

import com.bc.bcapi.service.T_Project_analysisService;
import com.bc.bcapi.service.T_User_elitesService;
import com.bc.bcapi.service.T_User_elites_relationService;
import com.bc.bcbuyerapihttp.common.UserContext;
import com.bc.bcmodel.BuyerUserInfo;
import com.bc.bcmodel.domain.T_User_buyer_infoModel;
import com.bc.bcmodel.req.*;
import com.bc.bcmodel.req.ElitesAnalysisListReq;
import com.bc.commoncore.util.StringUtils;
import com.bc.commonentity.common.JsonResult;
import com.bc.commonentity.enums.HttpReturnRnums;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Name ElitesController
 * @Description
 * @Author douhaichao
 * @Date 2018/8/29 13:29
 * @Version 1.0
 **/
@Api("精英管理/人才管理")
@RestController
@RequestMapping("elites")
public class ElitesController {

    @Autowired
    T_User_elitesService t_user_elitesService;

    @Autowired
    T_Project_analysisService t_project_analysisService;

    @Autowired
    T_User_elites_relationService t_user_elites_relationService;

    @ApiOperation("获取业务分析+代码分析列表")
    @RequestMapping(value = "getanalysislist", method = RequestMethod.POST)
    public JsonResult getAnalysisList(
            @RequestBody ProjectAnalysisListReq req) {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo != null) {
            req.setUser_id(userInfo.getUser_id());
        }
        return t_project_analysisService.getAnalysisList(req);
        //要返回是否登录，是否有权限发布业务分析
    }

    @ApiOperation("申请人才")
    @RequestMapping(value = "applyelits", method = RequestMethod.POST)
    public JsonResult applyElits(@RequestBody UserElitesApplyReq req) {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo != null) {
            req.setUser_id(userInfo.getUser_id());
        }
        return t_user_elitesService.applyElits(req);
    }

    @ApiOperation("查询人才信息{user_id为空是会取当前用户人才信息}")
    @RequestMapping(value = "getelitesinfo", method = RequestMethod.POST)
    public JsonResult getElitesInfo(@RequestBody ElitesInfoReq req) {
        if (req.getUser_id().isEmpty()) {
            BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
            if (userInfo != null) {
                req.setUser_id(userInfo.getUser_id());
            }
        }
        if (StringUtils.isEmpty(req.getUser_id())) {
            return new JsonResult(HttpReturnRnums.Success);
        }
        return t_user_elitesService.getElitesInfo(req);
    }

    @ApiOperation("发布/编辑分析{type_id 1项目分析 2代码分析}")
    @RequestMapping(value = "setanalysis", method = RequestMethod.POST)
    public JsonResult setAnalysis(@RequestBody AnalysisSetReq req) {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        req.setUser_id(userInfo.getUser_id());
        return t_project_analysisService.setAnalysis(req);
    }

    @ApiOperation("设置好评")
    @RequestMapping(value = "setgood", method = RequestMethod.POST)
    public JsonResult setGood(@RequestBody ProjectAnalysisSetGoodReq req) {
        //查询是否有参与过，如果没参与过执行，否则不处理。
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        req.setUser_id(userInfo.getUser_id());
        return t_project_analysisService.setGood(req);
    }

    @ApiOperation("获取人才列表")
    @RequestMapping(value = "geteliteslist", method = RequestMethod.POST)
    public JsonResult getElitesList(@RequestBody ElitesListReq req) {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo != null) {
            req.setUser_id(userInfo.getUser_id());
        }
        return t_user_elitesService.getElitesList(req);
    }

    @ApiOperation("设置支持人才+收藏人才")
    @RequestMapping(value = "seteliteslike", method = RequestMethod.POST)
    public JsonResult setElitesLike(@RequestBody
                                            ElitesFavoriteReq req) {
        BuyerUserInfo userInfo =
                UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        req.setMy_user_id(userInfo.getUser_id());
        return t_user_elites_relationService.setElitesLike(req);
    }

    @ApiOperation("我的专家-项目分析列表")
    @RequestMapping(value = "getmyelitesanalysislist", method = RequestMethod.POST)
    public JsonResult getMyElitesAnalysisList(@RequestBody
                                                      ElitesAnalysisListReq req) {
        BuyerUserInfo userInfo =
                UserContext.getCurrentContext().getLoginInfo();
        if (userInfo != null) {
            req.setCookie_uesr_id(userInfo.getUser_id());
        }
        if (req.getElites_user_id().isEmpty()) {
            req.setElites_user_id(req.getCookie_uesr_id());
        }
        return t_user_elitesService.getMyElitesAnalysisList(req);
    }

    @ApiOperation("通过项目ID获取评论详情")
    @RequestMapping(value = "getmyelitesanalysisbypid", method = RequestMethod.POST)
    public JsonResult getMyElitesAnalysisByPid(@RequestBody
                                                       ElitesByPidReq req) {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        req.setUser_id(userInfo.getUser_id());
        return t_user_elitesService.getMyElitesAnalysisByPid(req);
    }
}
